package com.dinzeer.godfox.effect;

import com.dinzeer.godfox.regsiter.GBEffectRegsitry;
import com.dinzeer.legendreliclib.lib.util.slashblade.SlashBladeUtil;
import mods.flammpfeil.slashblade.capability.slashblade.ISlashBladeState;
import mods.flammpfeil.slashblade.item.ItemSlashBlade;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.awt.*;
@Mod.EventBusSubscriber
public class GodFoxSave  extends MobEffect {
    public GodFoxSave() {
        super(MobEffectCategory.BENEFICIAL, Color.YELLOW.getRGB());
    }

    @SubscribeEvent
    public static void OnHurt(LivingHurtEvent event){

        if (event.getEntity().hasEffect(GBEffectRegsitry.GodFoxSave.get())) {

            if (event.getEntity().getMainHandItem().getItem() instanceof ItemSlashBlade) {
                ISlashBladeState state = SlashBladeUtil.getState(event.getEntity().getMainHandItem());

                int damageToBlock = (int) event.getAmount()/2;
                int count=state.getProudSoulCount();
                int delis=damageToBlock-(count/100);
                if (delis<=0){
                    state.setProudSoulCount(count-damageToBlock*100);
                    delis=0;
                }else {
                    state.setProudSoulCount(0);
                }

                event.setAmount(damageToBlock+delis);

            }
        }

    }

}
